#ifndef DATA_H
#define DATA_H

#include ".././search/SearchDef.h"

//FileInfo实体类(仿java模式)
class FileInfo {
public:
    int64_t fileId = 0;      // 对应数据库的file_id
    int64_t userId = 0;      // 对应user_id
    QString storagePath;     // 对应storage_path
    QDateTime uploadTime;    // 对应upload_time
    QString logicalName;     // 对应logical_name
    QString processType;     // 对应process_type
    int64_t fileSize = 0;    // 对应file_size
    QString fileHash;    // 对应file_hash(sha256)

    // 转换为搜索所需的元数据
    SearchMetaData<Page::PAGE_HISTORY> toHistoryMetaData() const {
        return SearchMetaData<Page::PAGE_HISTORY>(
            fileId,
            processType.toStdString(),
            logicalName.toStdString(),
            fileSize,
            uploadTime
            );
    }

    // 转换为搜索所需的元数据
    SearchMetaData<Page::PAGE_BACKUP> toBackUpMetaData() const {
        return SearchMetaData<Page::PAGE_BACKUP>(
            fileId,
            processType.toStdString(),
            logicalName.toStdString(),
            fileSize,
            uploadTime
            );
    }
};
Q_DECLARE_METATYPE(FileInfo)

class HistoryItemInfo : public FileInfo{
public:
    bool isUploaded = false;
    // 转换构造函数：允许从FileInfo构造HistoryItemInfo
    HistoryItemInfo(const FileInfo& other) {
        // 复制基类的所有成员变量
        fileId = other.fileId;
        userId = other.userId;
        storagePath = other.storagePath;
        uploadTime = other.uploadTime;
        logicalName = other.logicalName;
        processType = other.processType;
        fileSize = other.fileSize;
        fileHash = other.fileHash;

        // 子类成员设置默认值
        isUploaded = false;
    }

    // 复制构造函数（解决编译器警告）
    HistoryItemInfo(const HistoryItemInfo& other) {
        // 复制基类成员
        fileId = other.fileId;
        userId = other.userId;
        storagePath = other.storagePath;
        uploadTime = other.uploadTime;
        logicalName = other.logicalName;
        processType = other.processType;
        fileSize = other.fileSize;
        fileHash = other.fileHash;

        // 复制子类特有成员
        isUploaded = other.isUploaded;
    }

    // 默认构造函数
    HistoryItemInfo() = default;

    // 重载赋值运算符，允许用FileInfo对象给HistoryItemInfo赋值
    HistoryItemInfo& operator=(const FileInfo& other) {
        // 复制基类的所有成员变量
        fileId = other.fileId;
        userId = other.userId;
        storagePath = other.storagePath;
        uploadTime = other.uploadTime;
        logicalName = other.logicalName;
        processType = other.processType;
        fileSize = other.fileSize;
        fileHash = other.fileHash;

        return *this;
    }

    // 子类之间的赋值运算符
    HistoryItemInfo& operator=(const HistoryItemInfo& other) {
        if (this != &other) {
            // 复制基类成员
            fileId = other.fileId;
            userId = other.userId;
            storagePath = other.storagePath;
            uploadTime = other.uploadTime;
            logicalName = other.logicalName;
            processType = other.processType;
            fileSize = other.fileSize;
            fileHash = other.fileHash;

            // 复制子类特有成员
            isUploaded = other.isUploaded;
        }
        return *this;
    }
};
Q_DECLARE_METATYPE(HistoryItemInfo)

#endif // DATA_H
